package com.lagou.gateway.config;

import com.lagou.gateway.filter.LoggingFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.ServerHttpResponse;
import reactor.core.publisher.Mono;

/**
 * @author jacken
 * @date 2020/4/26 12:08 AM
 */
@Configuration
public class RateLimiterConfiguration {

  @Bean
  public KeyResolver ipKeyResolver() {
    return exchange -> Mono.just(exchange.getRequest().getHeaders().getFirst("X-REAL-IP"));
  }

  @Bean
  public LoggingFilter loggingFilter() {
    return new LoggingFilter();
  }

}
